<?php
require 'config.php';
require CAMINHO_SERVIDOR . 'funcoes.php';
require 'login.class.php';
$login = new Login();
if ($login->verificar(URL . 'admin/')) {
    if (isset($_GET["id_jogo"]) && isset($_GET["id_usuario"])) {
        $query = "SELECT placar_time_A,placar_time_B FROM tb_apostas WHERE id_jogo=" . $_GET["id_jogo"] . " AND id_usuario=" . $_GET["id_usuario"];
        $minhaAposta = $login->executaQueryRow($query);

        $query = "SELECT cam.descricao as campeonato,ta.img as img_a,tb.img as img_b,ta.nome as time_a,tb.nome as time_b,j.placar_time_A,j.placar_time_B  FROM tb_jogos j
                INNER JOIN tb_time ta ON ta.id_time=j.id_time_A
                INNER JOIN tb_time tb ON tb.id_time=j.id_time_B
                INNER JOIN tb_campeonato cam ON cam.id_campeonato=j.id_campeonato WHERE id_jogo=" . $_GET["id_jogo"];
        $jogo = $login->executaQueryRow($query);
    }
}
?>
<html>
    <head>
        <title>Apostar</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width">
        <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css">
        <link rel="stylesheet" type="text/css" href="bootstrap/css/classes.css">
    </head>
    <body>
        <div class="container">
            <div class="container-fluid margin10px">
                <a class="btn btn-info" href="<?php echo URL_ADMIN; ?>" >Início</a>
            </div>
            <div class="container-fluid col-md-4 col-md-offset-4">
                <?php
                if (isset($_GET["msg"])) {
                    if ($_GET["msg"] == 1) {
                        ?>
                        <div class="alert alert-success text-center">
                            Aposta Feita com sucesso!
                        </div>
                        <?php
                    } else {
                        ?>
                        <div class="alert alert-danger text-center">
                            Um erro ocorreu ao tentar efetuar a aposta!
                        </div>
                        <?php
                    }
                }
                ?>
            </div>
            <form action="<?php echo URL ?>processarAposta.php" method="POST">
                <input id="id_jogo" type="hidden" value="<?php echo $_GET["id_jogo"] ?>" name="id_jogo"/>
                <input id="id_usuario" type="hidden" value="<?php echo $_GET["id_usuario"] ?>" name="id_usuario"/>
                <div class="col-md-8 col-md-offset-2">
                    <div class="panel panel-primary">
                        <div class="panel-heading">
                            <h3 class="panel-title text-center">Apostar no Jogo</h3>
                        </div>
                        <div class="panel-body">
                            <div class="col-md-12 form-inline">
                                <table class="table table-hover">
                                    <thead>
                                        <tr>
                                            <td class="text-right"><?php echo $jogo["time_a"]; ?>
                                                <img src="imagens/<?php echo $jogo["img_a"] ?>"alt="<?php echo $jogo["time_a"] ?>" height="37" width="37">
                                            </td>
                                            <td style="width:170px">
                                                <input class="form-control" required placeholder="0" id="placar_a" name="placar_a" value="<?php echo $minhaAposta["placar_time_A"] ?>" type="text" />
                                            </td>
                                            <td class="text-center">x</td>

                                            <td style="width:170px">
                                                <input class="form-control" required placeholder="0" id="placar_b" name="placar_b" type="text" value="<?php echo $minhaAposta["placar_time_B"] ?>" />
                                            <td>
                                                <img src="imagens/<?php echo $jogo["img_b"] ?>"alt="<?php echo $jogo["time_b"] ?>" height="37" width="37">
                                                <?php echo $jogo["time_b"] ?>
                                            </td>
                                        </tr>
                                    </thead>
                                </table>
                            </div>
                            <button class="btn btn-info col-md-4 col-md-offset-1" type="submit">Apostar</button>
                            <a class="btn btn-info col-md-4  col-md-offset-2" href="<?php echo URL; ?>listaApostas.php?id_jogo=<?php echo $_GET["id_jogo"]; ?>&id_usuario=<?php echo $_GET["id_usuario"]; ?>" >Listar Apostas</a>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </body>
</html>